﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using Thaire.Investment.Domains.Master;

namespace Thaire.Investment.Repository
{
    public class ReferenceCodeRepo : BaseRepository<ReferenceCode, int>
    {

        public static readonly string DOMAIN_FINANCIAL_INSTRUMENTS = "FINANCIAL_INSTRUMENTS";
        public static readonly string BOND_TYPE = "BOND_TYPE";
        public static readonly string RATING = "RATING";
        public static readonly string ISSUER_TYPE = "ISSUER_TYPE";
        public static readonly string INSTRUCTION_STATUS = "INSTRUCTION_STATUS";
        public static readonly string PAYMENT_TYPE = "PAYMENT_TYPE";
        public static readonly string TRANSACTION_TYPE = "TRANSACTION_TYPE";
        public static readonly string EQUITY_TYPE = "EQUITY_TYPE";
        public static readonly string RELATED_NONRELATED = "RELATED_NONRELATED";
        public static readonly string KEEP_AT = "KEEP_AT";
        public static readonly string PHYSICAL = "PHYSICAL";
        public static readonly string DEPOSIT_TYPE = "DEPOSIT_TYPE";

        public static readonly string UNITTRUST_TYPE = "UNITTRUST_TYPE";
        public static readonly string TYPE_GROUP = "TYPE_GROUP";
        public static readonly string LOAN_TYPE = "LOAN_TYPE";
        public static readonly string LOAN_OBJECTIVE = "LOAN_OBJECTIVE";
        public static readonly string GUARANTEE_TYPE = "GUARANTEE_TYPE";
        public static readonly string ASSESSMENT_MORTGATE = "ASSESSMENT_MORTGATE";
        public static readonly string LOAN_STATUS = "LOAN_STATUS";
        public static readonly string HEADER_TRANSACTION_TYPE = "HEADER_TRANSACTION_TYPE";
        public ReferenceCodeRepo(ISession session)
            : base(session)
        {
        }

        public List<ReferenceCode> GetByDomain(String domainName)
        {
            return GetByDomain(domainName, true);
        }

        public List<ReferenceCode> GetByDomainOrderByID(String domainName)
        {
            return GetByDomain(domainName, true).OrderBy(x=>x.ID).ToList();
        }

        public List<ReferenceCode> GetByDomainOrderByValueTH(String domainName)
        {
            return GetByDomain(domainName, true).OrderBy(x => x.ValueTH).ToList();
        }

        public List<ReferenceCode> GetByDomainOrderByValueEN(String domainName)
        {
            return GetByDomain(domainName, true).OrderBy(x => x.ValueEN).ToList();
        }
        public List<ReferenceCode> GetByDomain(String domainName, bool includeHold)
        {
            if (includeHold)
            {
               

                return _session.QueryOver<ReferenceCode>().Where(x => x.Domain == domainName).List().ToList();

            }
            else
            {
                return _session.QueryOver<ReferenceCode>().Where(x => (x.Domain== domainName) && ( x.Hold ==null)).List().ToList();
            }
        }



    
    }
}
